<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of convertToSdp</title>
  <meta name="keywords" content="convertToSdp">
  <meta name="description" content="Converts Syms variables into sdpvar().">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">source</a> &gt; convertToSdp.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for source&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>convertToSdp
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Converts Syms variables into sdpvar().</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [ alfa ] = convertToSdp( alfa ) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment">Converts Syms variables into sdpvar().

This function looks for Syms variables in alfa string vector and replace
them with sdpvar() variables.

Prorotype: [alfa] = convertToSdp(alfa).

Input:     alfa - is a equation string vector with Syms variable.

Output:    alfa -same alfa's syntax but with sdpvar() variable istead of Syms.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="cell2str.html" class="code" title="function string = cell2str( cellstr )">cell2str</a>	Converts a 2-D cell array of strings to a string in MATLAB syntax.</li><li><a href="strsplit.html" class="code" title="function parts = strsplit( splitstr, str, option )">strsplit</a>	Split string into pieces.</li></ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <span class="comment">%Converts Syms variables into sdpvar().</span>
0002 <span class="comment">%</span>
0003 <span class="comment">%This function looks for Syms variables in alfa string vector and replace</span>
0004 <span class="comment">%them with sdpvar() variables.</span>
0005 <span class="comment">%</span>
0006 <span class="comment">%Prorotype: [alfa] = convertToSdp(alfa).</span>
0007 <span class="comment">%</span>
0008 <span class="comment">%Input:     alfa - is a equation string vector with Syms variable.</span>
0009 <span class="comment">%</span>
0010 <span class="comment">%Output:    alfa -same alfa's syntax but with sdpvar() variable istead of Syms.</span>
0011 
0012 <span class="comment">%Claudio Fantacci &amp; Alessandro Martini.</span>
0013 
0014 <a name="_sub0" href="#_subfunctions" class="code">function [ alfa ] = convertToSdp( alfa )</a>
0015 
0016 sdpIndex = 1;
0017 
0018 <span class="keyword">for</span> i = 1:length(alfa)
0019     target = char(alfa(i));
0020     <span class="keyword">if</span> alfa(i) ~= 0 &amp;&amp; isempty(strfind(target,<span class="string">'+'</span>)) &amp;&amp; isempty(strfind(char(alfa(i)),<span class="string">'-'</span>)) &amp;&amp; isempty(strfind(char(alfa(i)),<span class="string">'*'</span>))
0021         names{sdpIndex} = target;
0022         sdpalfa{sdpIndex} = sdpvar(1);
0023         sdpIndex = sdpIndex + 1;
0024     <span class="keyword">end</span>
0025 <span class="keyword">end</span>
0026 
0027 <span class="keyword">for</span> i = 1:length(alfa)
0028     <span class="keyword">if</span> ~isempty(strfind(char(alfa(i)),<span class="string">'+'</span>)) || ~isempty(strfind(char(alfa(i)),<span class="string">'-'</span>)) || ~isempty(strfind(char(alfa(i)),<span class="string">'*'</span>))
0029         chr = strrep(char(alfa(i)),<span class="string">'+'</span>,<span class="string">' +'</span>);
0030         chr = strrep(chr,<span class="string">'-'</span>,<span class="string">' -'</span>);
0031         chr = strrep(chr,<span class="string">'*'</span>,<span class="string">'* '</span>);
0032         pieces = <a href="strsplit.html" class="code" title="function parts = strsplit( splitstr, str, option )">strsplit</a>(<span class="string">' '</span>,chr);
0033         <span class="keyword">for</span> k=1:length(names)
0034             nameToCheck = names{k};
0035             found = false;
0036             index = 1;
0037             <span class="keyword">while</span> ~found &amp;&amp; index &lt;= length(pieces)
0038                 pieceToControl = char(pieces{index});
0039                 <span class="keyword">if</span> ~isempty(strfind(pieceToControl,nameToCheck))
0040                     pieces{index} = sdpalfa{k};
0041                     found = true;
0042                 <span class="keyword">else</span>
0043                     index = index + 1;
0044                 <span class="keyword">end</span>
0045             <span class="keyword">end</span>
0046         <span class="keyword">end</span>
0047         result = <span class="string">''</span>;
0048         <span class="keyword">for</span> k = 1:length(pieces)
0049             <span class="keyword">if</span> isempty(strfind(class(pieces{k}),<span class="string">'sdpvar'</span>))
0050                 result = strcat(result,char(pieces{k}));
0051             <span class="keyword">else</span>
0052                 string = <a href="cell2str.html" class="code" title="function string = cell2str( cellstr )">cell2str</a>(names{k});
0053                 result = strcat(result,string);
0054             <span class="keyword">end</span>
0055         <span class="keyword">end</span>
0056         command = strcat(<span class="string">'sdpalfa{'</span>,num2str(i),<span class="string">'}='</span>,result,<span class="string">';'</span>);
0057         eval(command);
0058     <span class="keyword">end</span>
0059     
0060 <span class="keyword">end</span>
0061 
0062 <span class="keyword">return</span>;</pre></div>
<hr><address>Generated on Mon 12-Oct-2009 21:15:56 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>